package com.hq.controller;

import com.hq.entity.QuestionType;
import com.hq.entity.ResultVo;
import com.hq.entity.Score;
import com.hq.entity.ScoreVO;
import com.hq.service.ScoreService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/score")
@Slf4j
public class ScoreController {

    @Autowired
    private ScoreService scoreService;

    //编辑分数
    @RequestMapping("/edit")
    public ResultVo edit(@RequestBody ScoreVO scorevo){
        log.info("修改的分数{}",scorevo.getScore());
        ResultVo vo=new ResultVo();
        if(scoreService.editScore(scorevo)>0){
            vo.setCode(200);
            vo.setMsg("修改成功！");
        }else{
            vo.setCode(500);
            vo.setMsg("修改失败！");
        }
        return vo;
    }

    // 批量删除题型
    @RequestMapping("/dels")
    public ResultVo dels(String ids){
        log.info("批量删除的题型id{}",ids);
        ResultVo vo=new ResultVo();
        if(scoreService.delScores(ids)>0){
            vo.setCode(200);
            vo.setMsg("删除成功！");
        }else{
            vo.setCode(500);
            vo.setMsg("删除失败！");
        }
        return vo;
    }

    // 单行删除题型
    @RequestMapping("/del")
    public ResultVo del(int id){
        log.info("删除的题型id{}",id);
        ResultVo vo=new ResultVo();
        if(scoreService.delScore(id)>0){
            vo.setCode(200);
            vo.setMsg("删除成功！");
        }else{
            vo.setCode(500);
            vo.setMsg("删除失败！");
        }
        return vo;
    }

    //试卷查询
    @RequestMapping("/list")
    public Map<String,Object> list(int page, int size){
        log.info("分页查询");
        return scoreService.findByPage(page,size);
    }

    //交卷
    @RequestMapping("/add")
    public ResultVo add(Score score){
        log.info("交卷信息{}",score);
        ResultVo vo=new ResultVo();
        if(scoreService.add(score)>0){
            vo.setCode(200);
            vo.setMsg("交卷成功！");
        }else{
            vo.setCode(500);
            vo.setMsg("交卷失败！");
        }
        return vo;

    }
}
